//
//  HomeChooseCityController.m
//  QuickCure1
//
//  Created by 李江波 on 2016/10/31.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "HomeChooseCityController.h"

#import "Province.h"
#import "HomeCityViewController.h"

@interface HomeChooseCityController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic ,strong) NSArray<Province *> *citys;

@end


static NSString *cellID = @"CELLID";
@implementation HomeChooseCityController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"选取省份";
    
    [self loadData];
    
    [self setupUI];
}


/**
 加载数据
 */
-(void)loadData{

    NSString *path = [[NSBundle mainBundle]pathForResource:@"province.plist" ofType:nil];
    
    NSArray *array = [NSArray arrayWithContentsOfFile:path];
    
    _citys = [Province citiesWithArray:array];
    
    
}

-(void)setupUI{

    UITableView *tableview = [[UITableView alloc]initWithFrame:self.view.bounds];
    
    [self.view addSubview:tableview];
    
    tableview.showsVerticalScrollIndicator= NO;
    
    tableview.delegate = self;
    tableview.dataSource = self;
    
    [tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
}

#pragma mark : - 数据源方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.citys.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    cell.textLabel.text = self.citys[indexPath.row].name;
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    HomeCityViewController *cityView = [[HomeCityViewController alloc]init];
    
    cityView.cityModels = self.citys[indexPath.row].cities;
    
    [self.navigationController pushViewController:cityView animated:YES];
    
}

@end
